


namespace ModuleData
{

  const int PACKAGE_SIZE = 256;

  // GPS sentence类型枚举
  enum {
    GPS_SENTENCE_VOID = -1,
    GPS_SENTENCE_GPGSV,
    GPS_SENTENCE_GPGSA,
    GPS_SENTENCE_GPGGA,
    GPS_SENTENCE_GPRMC,
    GPS_SENTENCE_GPVTG,
    GPS_SENTENCE_GPGLL,
    GPS_SENTENCE_GPZDA,
    GPS_SENTENCE_GPDTM,

    GPS_SENTENCE_MAX
  };

  class GPSsplitter;

  class GPSdata_error
  {
  public:
    GPSdata_error( int _id, void *_info=NULL );

    int get_errid( void ) const { return error_id; }

    void* get_info( void ) const { return info; }

    const char* get_error_msg( void ) { return error_info[ error_id ]; }

    enum {
      INIT_DATA_ORIG_TOO_LONG = 0,
      INIT_DATA_PASER_FAIL,
      ERROR_MAX
    };

  private:
    int error_id;
    void* info;

    static const char *error_info[ ERROR_MAX+1 ];
  };

  typedef void* (*ObjGen)( int, const char* );
  typedef void  (*ObjDel)( int, void * );

  extern ObjGen default_gen;
  extern ObjDel default_del;

  class GPSdata
  {
    ObjGen obj_creator;
    ObjDel obj_releaser;
  public:
    GPSdata( ObjGen g_func=default_gen, ObjDel d_func=default_del );

    // 传入包，然后经过解析变成内在的表字段
    void                  init_data( char* _orig, GPSsplitter& _paser ) throw(GPSdata_error);

    // 此GPS sentence的类型
    int                   get_type( void ) const { return sentence_type; }

    // 字符串格式的包
    const char*           get_raw_data( void ) const { return orig_data; }

    // 解析后的字段
    void*                 get_value( int ) const;

    // 查询状态
    bool                  is_init( void ) const { return is_initialized; }
    bool                  is_actived( void ) const { return is_activated; }

    friend class GPSsplitter;

  private:
    // 此几个函数提供给GPSsplitter使用
    void                  set_type( int _type ) { sentence_type = _type; }
    void                  set_value( int, const char* );
    void                  set_avaiable( void ) { is_activated = true; }


    char                  orig_data[ PACKAGE_SIZE ]; // 原始形态的包
    int                   sentence_type;	     // 定位信息的类型
    std::map<int, void*>  data_info;		     // 用表来进行储存信息

    bool                  is_initialized;
    bool                  is_activated;
  }; 


  // get_value的key
  enum {
    // ****  GSV  ****
    GSV_NUMBER_OF_SENTENCES,
    GSV_SENTENCE_INDEX,
    GSV_NUMBER_OF_SATELLITES,

    GSV_SATELLITES_INFO,
    // ****  GSV  ****


    // ****  GSA  ****
    GSA_SELECTION_MODE,
    GSA_FIX_MODE,
    GSA_SATELLITES_FOR_FIX,
    GSA_PDOP,
    GSA_HDOP,
    GSA_VDOP,
    // ****  GSA  ****


    // ****  GGA  ****
    GGA_UTC,
    GGA_LATITUDE,
    GGA_LONGITUDE,
    GGA_FIX_QUALITY,
    GGA_SATELLITES_FOR_FIX,
    GGA_HDOP,
    GGA_ALTITUDE,
    GGA_HEIGHT_OF_GEOID,
    GGA_DGPS_TIME_DIFFER,
    GGA_DGPS_STATION_ID,
    // ****  GGA  ****


    // ****  RMC  ****
    RMC_UTC,
    RMC_STATUS,
    RMC_LATITUDE,
    RMC_LONGITUDE,
    RMC_SPEED,
    RMC_TRACK_ANGLE,
    RMC_DATE,
    RMC_MAGNETIC,
    RMC_FIX_TYPE,
    // ****  RMC  ****


    // ****  VTG  ****
    VTG_TRACK_ANGLE,
    VTG_TRACK_MAGNETIC,
    VTG_SPEED_IN_KNOT,
    VTG_SPEED_IN_KM,
    VTG_FIX_TYPE,
    // ****  VTG  ****


    // ****  GLL  ****
    GLL_LATITUDE,
    GLL_LONGITUDE,
    GLL_UTC,
    GLL_STATUS,
    GLL_FIX_TYPE,
    // ****  GLL  ****


    // ****  ZDA  ****
    ZDA_UTC,
    ZDA_DATE,
    ZDA_LOCAL_ZONE,
    // ****  ZDA  ****
  };


}
